<template>
	<view class="page">
		<Header :title="'我的'" :name="isBack"></Header>
		<view class="wrap">
			<!-- 	<view class="u-tabs-box">
				<u-tabs :list="list" @click="click"></u-tabs>
			</view> -->
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y class="scrollHeight" @scrolltolower="ReachBottom">
						<view class="page_box">
							<view class="order" v-for="(res, index) in orderList" :key="res.id" @click="goDetail(res)">
								<view class="top">
									<view class="left">
										<view class="store">{{titleKey}}编号：{{ res.id }}</view>
									</view>
									<view  v-if="res.putawaySure==1">
										<view  v-if="res.scheme==0">
											<view class="right1" v-if="res.adoptSurplusMonth>0">
												饲料充足余{{res.adoptSurplusMonth}}月
											</view>
											<view class="right1" v-else-if="res.adoptSurplusMonth==0">
												饲料费已不足
											</view>
											<view class="right1" v-else-if="res.adoptSurplusMonth<0">
												饲料费逾期{{res.adoptSurplusMonth}}月
											</view>
										</view>
										<view  v-if="res.scheme==1">
											<view class="right1" >
												B方案认养蜂箱
											</view>
										</view>
										<view  v-if="res.scheme==2">
											<view class="right1" >
												C方案认养蜂箱
											</view>
										</view>
									</view>
									<view  v-else>
										<view class="right1" >
										等待养殖户处理
										</view>
									</view>
								</view>
								<view class="item" :key="index">
									<view class="left">
										<view class="dianpu">
											<!-- {{ res.store }} -->
										</view>
										<image :src="res.fosterProduct.imgUrl" mode="aspectFill"
											style="width: 200rpx;height: 200rpx;border-radius: 10rpx;"></image>
									</view>
									<view class="content">
										<view class=""
											style="display: flex;width: 400rpx;justify-content: space-between;">
											<view style="font-size: 28rpx;">{{ res.fosterProduct.varietyName + res.fosterProduct.number}}号</view>
											<view class="price"><span style="font-size: 32rpx;color: red;">￥</span>
												<span
													style="font-size: 40rpx;font-weight: 600;color: red;">{{ res.fosterProduct.money }}</span>
											</view>
										</view>
										<view class="" style="width: 400rpx;display: flex;justify-content: space-between;">
											<view class="type">每月产出{{ parseInt(res.fosterProduct.minOutput * 500) }} 克</view>
											<view class="huis" v-if="res.putawaySure==1" @click="tohuishou(res)">回收</view>
										</view>
									</view>

								</view>
							</view>
							<!-- <view class="loadmoreBox" v-if="orderList!=0">
								<u-loadmore :status="status" :icon-type="iconType"  />
							</view> -->
							<view style="height: 250rpx;" v-if="orderList!=0"></view>
							<view class="emptyBox" v-if="orderList.length==0">
								<image class="emptyIcon" src="../../../static/empty.png" mode="widthFix"></image>
								<view class="emptyText">
									您还没有相关{{titleKey}}！
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<view class="buyBox" :class="{'buyBox2':isBack}">
			<view class="buyBtn" @click="goList()">去{{titleKey}}</view>
		</view>
	</view>
</template>

<script>
	import Header from '@/components/header/header.vue'
	export default {
		props: {
			isBack: {
				typeof: String,
				default: 'arrow-left',
			},
		},
		data() {
			return {
				background: {
					backgroundColor: '#21B070'
				},
				orderList: [],

				current: 0,
				swiperCurrent: 0,
titleKey:uni.getStorageSync('titleKey'),
				status: 'loadmore',
				iconType: 'flower',
				
				pageNum:1,
				total:0,
				pageSize:10,
			};
		},
		onLoad() {

		},
		created() {
			this.getOrderList();
		},
		components: {
			Header
		},
		computed: {},
		methods: {
			async tohuishou(e){
				let res = await this.$api.request('farmer/foster/recycling', 'get',{id:e.id})
				if(res.code=='200'){
					uni.showToast({
						title:'申请成功，等待工作人员处理',
						icon:'none'
					})
				}
			},
			goList(){
				uni.navigateTo({
					url: '/pages/index/adopt/adoptAll' 
				})
			},
			// 跳转详情
			goDetail(e) {
				uni.navigateTo({
					url: '/pages/my/adopt/adoptDate/adoptDate?id=' + e.id
				})
			},
			// 页面数据
			async getOrderList() {
				let params={
					pageNum:this.pageNum,
					pageSize:this.pageSize
				}
				//我的认养列表
				let res = await this.$api.request('farmer/user/adopt/myList', 'get',params)
				if(this.pageNum==1){
					this.orderList=res.data.list
				}else{
					this.orderList.push(...res.data.list)
				}
			
				this.total=res.total
				if (this.orderList.length == this.total) {
					this.status = 'nomore'
				} else {
					this.status = 'loading'
				};
			},
			ReachBottom() {
				let that = this;
				if (this.orderList.length == this.total || this.orderList.length > this.total) {
					this.status = 'nomore'
					return; //没有更多数据时  中止执行后续代码
				}
				console.log('触发了')

				this.status = 'loading'; //设置触底加载组件状态 为正在加载
				this.pageNum = ++this.pageNum; //请求下一页

				that.getOrderList(); //请求的接口数据
				if (this.orderList.length == this.total) {
					this.status = 'nomore'
				} else {
					this.status = 'loading'
				};

			},
		}
	};
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		/* background-color: #f2f2f2; */
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.huis{
		height: 40rpx;
		border-radius: 100rpx;
		width: 100rpx;
		background: linear-gradient(-49deg, #FE471E, #D40101);
		color: #fff;
		font-size: 28rpx;
		text-align: center;
		line-height: 40rpx;
		margin-top: 60rpx;
	}
	.buyBox {
		padding-right:20rpx;
		box-sizing: border-box;
		width: 100%;
		height:250rpx;
		position: fixed;
		bottom:0rpx;
		display: flex;
		justify-content: center;
		background-color: #fff;
		box-shadow: 0rpx -5rpx 8rpx 0rpx rgba(153,153,153,0.3);
		&.buyBox2{
			height:120rpx;
		}
	
		.buyBtn{
			margin-top: 20rpx;
			height: 78rpx;
			border-radius: 100rpx;
			width: 80%;
			background: linear-gradient(-49deg, #FE471E, #D40101);
			color:#fff;
			font-size: 36rpx;
			text-align: center;
			line-height:78rpx;
			font-weight: bold;
		}
	}
	.page {
		background-color: #f5f5f5;
		height: 100vh;
		overflow: hidden;
	}

	.loadmoreBox {
		margin: 0 auto;
		margin-bottom: 180rpx;
	}

	.scrollHeight {
		height: 100%;
		width: 100%;
	}

	.emptyBox {
		width: 100%;
		height: 50vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.emptyText {
			font-size: 32rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.emptyIcon {
			width: 20%;

		}
	}

	.tabs {
		width: 750rpx;
		height: 88rpx;
		background-color: #fff;
		z-index: 600;
	}

	.order {
		background-color: #ffffff;
		margin: 20rpx 30rpx;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 30rpx;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;
			padding-bottom: 20rpx;
			border-bottom: 1px solid #ececec;

			.left {
				display: flex;
				align-items: center;

				.store {
					font-size: 24rpx;
					color: #999999;
				}
			}

			.right {
				color: #26acf5;
			}

			.right1 {
				color: #f55726;
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;

			.left {
				margin-right: 30rpx;

				image {
					width: 130rpx;
					height: 130rpx;
					// border-radius: 10rpx;
				}

				.dianpu {
					font-size: 26rpx;
					line-height: 36rpx;
					color: #333333;
					margin-bottom: 16rpx;
				}
			}

			.content {
				margin-top: 56rpx;

				.title {
					font-size: 28rpx;
					line-height: 36rpx;
					color: #333333;
				}

				.type {
					margin: 20rpx 0 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}

				.delivery-time {
					color: #e5d001;
					font-size: 24rpx;
				}
			}

			.right {
				margin-left: 42rpx;
				margin-top: 52rpx;
				text-align: right;
				color: #333333;
				font-size: 24rpx;
				line-height: 30rpx;
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			display: flex;

			justify-content: flex-end;
			align-items: center;

			.btn {
				line-height: 58rpx;
				width: 140rpx;
				border-radius: 28rpx;
				border: 1rpx solid #999999;
				font-size: 24rpx;
				text-align: center;
				color: #333333;
				margin-left: 20rpx;
			}

			.evaluate {
				color: #00aaff;
				border: 1rpx solid #00aaff;
			}
		}
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 164rpx;
			height: 164rpx;
			border-radius: 50%;
			margin-bottom: 20rpx;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: 100vh;
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
</style>